package com.csdj.rest.config;

import com.csdj.common.aop.AbstractRoleParase;
import com.csdj.common.constant.CommonConstant;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

@Component
@Aspect
public class RoleParase extends AbstractRoleParase {

    private Logger log = LoggerFactory.getLogger(this.getClass().getName());
    @Override
    public boolean checkRole(String[] roles) {
        final HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        String uid = request.getHeader(CommonConstant.HEADER_USER_ID);
        log.info("role aop parser");
        return true;
    }

    @Override
    public String getLoginUrl() {
        return "/user/login";
    }
}
